package com.aigc.sclassroom.controller;

import com.aigc.sclassroom.mapper.SurveyMapper;
import com.aigc.sclassroom.pojo.Feedback;
import com.aigc.sclassroom.pojo.Result;
import com.aigc.sclassroom.pojo.ScorePercent;
import com.aigc.sclassroom.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/feedback")
public class FeedbackController {
    @Autowired
    private FeedbackService feedbackService;
    @Autowired
    private SurveyMapper surveyMapper;

    //获取提交学生反馈表信息
    @GetMapping
    public Result<List<Feedback>> list(Long surveyId){
        List<Feedback> fs=feedbackService.list(surveyId);
        return Result.success(fs);
    }

    //获取问卷评分问题百分比
    @GetMapping("/getPercent")
    public Result<ScorePercent> persentList(Long surveyId){
        List<Feedback> feedback = feedbackService.list(surveyId);
        ScorePercent scorePercent = new ScorePercent();
        int [] count1 = {0,0,0,0,0,0};
        int [] count2 = {0,0,0,0,0,0};
        int [] count3 = {0,0,0,0,0,0};
        int [] count4 = {0,0,0,0,0,0};
        int [] count5 = {0,0,0,0,0,0};
        for (int i = 0; i < feedback.size(); i++) {
            //满意度填写情况
            if(feedback.get(i).getSatisfaction()==5){
                count1[0]++;
            }else if(feedback.get(i).getSatisfaction()==4){
                count1[1]++;
            }else if (feedback.get(i).getSatisfaction()==3){
                count1[2]++;
            }else if (feedback.get(i).getSatisfaction()==2){
                count1[3]++;
            }else if (feedback.get(i).getSatisfaction()==1){
                count1[4]++;
            }else {
                count1[5]++;
            }
            //讲课速度填写情况
            if(feedback.get(i).getSpeed()==5){
                count2[0]++;
            }else if(feedback.get(i).getSpeed()==4){
                count2[1]++;
            }else if (feedback.get(i).getSpeed()==3){
                count2[2]++;
            }else if (feedback.get(i).getSpeed()==2){
                count2[3]++;
            }else if (feedback.get(i).getSpeed()==1){
                count2[4]++;
            }else {
                count2[5]++;
            }
            //互动程度填写情况
            if(feedback.get(i).getInteraction()==5){
                count3[0]++;
            }else if(feedback.get(i).getInteraction()==4){
                count3[1]++;
            }else if (feedback.get(i).getInteraction()==3){
                count3[2]++;
            }else if (feedback.get(i).getInteraction()==2){
                count3[3]++;
            }else if (feedback.get(i).getInteraction()==1){
                count3[4]++;
            }else {
                count3[5]++;
            }
            //环境填写情况
            if(feedback.get(i).getEnvironment()==5){
                count4[0]++;
            }else if(feedback.get(i).getEnvironment()==4){
                count4[1]++;
            }else if (feedback.get(i).getEnvironment()==3){
                count4[2]++;
            }else if (feedback.get(i).getEnvironment()==2){
                count4[3]++;
            }else if (feedback.get(i).getEnvironment()==1){
                count4[4]++;
            }else {
                count4[5]++;
            }
            //理解度填写情况
            if(feedback.get(i).getUnderstand()==5){
                count5[0]++;
            }else if(feedback.get(i).getUnderstand()==4){
                count5[1]++;
            }else if (feedback.get(i).getUnderstand()==3){
                count5[2]++;
            }else if (feedback.get(i).getUnderstand()==2){
                count5[3]++;
            }else if (feedback.get(i).getUnderstand()==1){
                count5[4]++;
            }else {
                count5[5]++;
            }
        }
        scorePercent.setSatisfactionCount(count1);
        scorePercent.setSpeedPercentCount(count2);
        scorePercent.setInteractionCount(count3);
        scorePercent.setEnvironmentCount(count4);
        scorePercent.setUnderstandCount(count5);
        Long courseManageId = surveyMapper.selectCourseManageIdBysurveyId(surveyId);
        scorePercent.setCountSum(surveyMapper.selectSubmitCount(surveyId,courseManageId));
        return Result.success(scorePercent);
    }

    //学生填写反馈
    @PostMapping
    public Result add(@RequestBody Feedback feedback){
        feedbackService.add(feedback);
        return Result.success();
    }

}
